//
//  LGHeartRhythmWarnCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2024/7/30.
//

#import "LGHeartRhythmWarnCell.h"

@interface LGHeartRhythmWarnCell()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)NSMutableArray *itemArray;

@end

@implementation LGHeartRhythmWarnCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self.contentView addSubview:self.baseView];
        [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.equalTo(self.contentView);
            make.left.equalTo(self.contentView).offset(viewPix(16));
            make.right.equalTo(self.contentView).offset(-viewPix(16));
            make.height.equalTo(@(0));
        }];
    }
    return  self;
}

-(void)setDataArray:(NSArray *)dataArray{
    _dataArray = dataArray;
    CGFloat top = viewPix(13);
    for (NSInteger i=0; i<dataArray.count; i++) {
        top = [self itemViewWithData:dataArray[i] index:i top:top];
    }
    top = ((dataArray.count-1)%2 == 0)?top+viewPix(35):top+viewPix(13);
    [self.baseView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(top));
    }];
}

-(CGFloat)itemViewWithData:(NSDictionary *)dataDic index:(NSInteger)index top:(CGFloat)top{
    CGFloat left = (index%2 == 0)?viewPix(16):(Screen_W-viewPix(36))/2.0+viewPix(15);
    
    UILabel *titleLabel = [UILabel lableWithText:LGNSString(dataDic[@"title"]) colorString:@"#909399" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    titleLabel.frame = CGRectMake(left, top, (Screen_W-viewPix(36))/2.0-viewPix(70), viewPix(22));
    [self.baseView addSubview:titleLabel];
    [self.itemArray addObject:titleLabel];
    
    UILabel *contentLabel = [UILabel lableWithText:LGNSString(dataDic[@"count"]) colorString:@"#282828" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    [self.baseView addSubview:contentLabel];
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLabel.mas_right).offset(viewPix(5));
        make.centerY.equalTo(titleLabel);
    }];
    [self.itemArray addObject:contentLabel];
    
    top = (index%2 == 0)?kMinY(titleLabel.frame):kMaxY(titleLabel.frame)+viewPix(15);
    return top;
}

-(NSMutableArray *)itemArray{
    if(!_itemArray){
        _itemArray = [NSMutableArray array];
    }
    return _itemArray;
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc]init];
        _baseView.backgroundColor = [UIColor colorWithString:@"#F4F9FA"];
        _baseView.cornerRidus = 7;
    }
    return _baseView;
}

@end
